package com.day3.one;

import java.lang.reflect.Field;

public class Test {
    public static void main(String[] args) throws Exception {

//        Class<Fan> fanClass = Fan.class;
//        System.out.println("fanClass = " + fanClass);
//
//        Fan fan = new Fan();
//        Class<? extends Fan> aClass = fan.getClass();
//        System.out.println("aClass = " + aClass);
//        Class<?> aClass1 = Class.forName("com.day3.Two.Fan");
//        System.out.println("aClass1 = " + aClass1);

        Class<Fan> fanClass = Fan.class;
//        Fan fan = fanClass.newInstance();
//        Fan fan1 = fanClass.newInstance();
//        Field fbs = fanClass.getDeclaredField("fbs");
//        System.out.println("fbs = " + fbs);
//        Field age = fanClass.getDeclaredField("age");
//        System.out.println("age = " + age);
//        Field[] declaredFields = fanClass.getDeclaredFields();
//        for (Field declaredField : declaredFields) {
//            System.out.println("declaredField = " + declaredField);
//        }
//        Field[] fields = fanClass.getFields();
//        for (Field field : fields) {
//            System.out.println("field = " + field);
//        }
        Fan fan = fanClass.newInstance();
        System.out.println("fan = " + fan);
        Field fbs = fanClass.getDeclaredField("fbs");
        fbs.set(fan,"樊博士");
        System.out.println("fbs = " + fbs);

        Object o = fbs.get(fan);
        System.out.println("o = " + o);

        Field age = fanClass.getDeclaredField("age");
        age.setAccessible(true);
        age.set(fan,18);
        System.out.println("fan = " + fan);
        Object o1 = age.get(fan);
        System.out.println("o1 = " + o1);


    }
}

class Fan1{
    private String sex;
    public  String address;
}
class Fan extends Fan1{
    private String fbs;
    public Integer age;

    @Override
    public String toString() {
        return "Fan{" +
                "fbs='" + fbs + '\'' +
                ", age=" + age +
                '}';
    }
}